package miracle.joker.design.command.demo2;

public class Invoker {
    private CommandQueue commandQueue = new CommandQueue();

    private Document document = new Document();

    public void addText(String text) {
        Command command = new AddTextCommand(document, text);
        command.execute();
        commandQueue.pushUndoCommand(command);
    }

    public void delete() {
        Command command = new DeleteTextCommand(document);
        command.execute();
        commandQueue.pushUndoCommand(command);
    }

    public void moveCursor(int steps) {
        Command command = new MoveCursorCommand(document, steps);
        command.execute();
        commandQueue.pushUndoCommand(command);
    }

    public void undo() {
        Command command = new UndoCommand(commandQueue);
        command.execute();
    }

    public void redo() {
        Command command = new RedoCommand(commandQueue);
        command.execute();
    }

    public String getContent() {
        return document.getContent();
    }
}
